<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <script src="/js/jquery.min.js" type="text/javascript"></script>
  <link href="/js/crop/jquery-ui-1.7.2.custom-min.css" rel="stylesheet" type="text/css"/>

  <script src="/js/crop/jquery-ui-1.7.2.custom.min.js" type="text/javascript"></script>
  <script src="/js/crop/jquery.cropzoom.js" type="text/javascript"></script>
  <style>
  body {
    font-size: 12px;
  }

  #crop_container {
    FLOAT: left
  }

  #msg {
    color: red;
  }

  .menu {
    float: left;
    height: 50px;
    line-height: 50px;
  }

  .menu input {
    background-color: #F8FCFE;
    border: #D6EDF8 solid 1px;

  }

  .result {
    border: #D6EDF8 solid 1px;
    MARGIN: 0px 0px 0px 10px;
    WIDTH: 400px;
    FLOAT: left;
    HEIGHT: 300px;
    text-align: center;
  }

  </style>
  <SCRIPT type=text/javascript>
    $(document).ready(function() {

      var cropzoom = $('#crop_container').cropzoom({
        width:400,
        height:300,
        bgColor: '#fff',
        enableRotation:true,
        enableZoom:true,
        selector:{
          w:${params.w==""?130:params.w},
          h:${params.h==""?160:params.h},
          maxWidth:${params.w==""?130:params.w},
          maxHeight:${params.h==""?160:params.h},
          aspectRatio:true,
          showPositionsOnDrag:false,
          showDimetionsOnDrag: true,
          centered:true,
          borderColor:'blue',
          borderColorHover:'yellow'
        },
        image:{
          source:'${params?.imgurl}',
          width: ${params?.imgw},
          height:${params?.imgh},
          minZoom:10,
          maxZoom:150
        }
      });
      $('#crop').click(function() {
        $("#msg").html("<img src='/images/up.gif' border='0'/>当前操作正在处理中，请稍后....");
        cropzoom.send('/upload/imgCrop', 'POST', {}, function(path) {
          if (path.indexOf("ERROR") > -1) {
            alert(path);
            return
          }

          $("#msg").html("处理完成。");
          $("#imgCrop").val(path);
          $('.result').find('img').remove();
          var img = $('<img />').attr('src', path + "?rand=" + Math.random());
          $('.result').find('.txt').hide().end().append(img);
        });
      });
      $('#restore').click(function() {
        $('.result').find('img').remove();
        $('.result').find('.txt').show()
        $("#msg").html("");
        cropzoom.restore();
      });

    });

    function ok() {
      opener.imgCropSucceed($("#imgCrop")[0].value);
      window.close();

    }

  </SCRIPT>
</head>
<body>
<div class="boxes">
  <div id="crop_container"></div>
  <div class="result">
    <div class="txt">裁剪后的图片预览区域</div>
  </div>
  <div class="cleared"></div>
</div>

<div class="menu">
  <span id="msg"></span>&nbsp;&nbsp; <input type="button" name="crop" id="crop" value="裁剪"/>&nbsp;&nbsp;<input type="button" name="restore" id="restore" value="还原"/> &nbsp;&nbsp; <input type="button" name="ok" id="ok" value="裁剪完成" onclick="ok();"/>
</div>
<input type="hidden" name="imgCrop" id="imgCrop"/>
</body>
</html>
